﻿using Codeplus.Library.Constants;

namespace Codeplus.Library.Data
{
    public class DatabaseInfo
    {
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Datasource { get; set; }
        public string InitialCatalog { get; set; }
    }

    public class AppDataContext
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static CodeplusEntities GetContext()
        {
            var databaseInfo = GetDatabaseInfo();
            var context =
                new CodeplusEntities(
                    string.Format(Config.ConnectionString, databaseInfo.UserName, databaseInfo.Password,
                                  databaseInfo.Datasource,
                                  databaseInfo.InitialCatalog));
            context.ContextOptions.LazyLoadingEnabled = false;
            return context;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static DatabaseInfo GetDatabaseInfo()
        {
            var databaseInfo = new DatabaseInfo();
            if (Config.DebugMode)
            {
                databaseInfo.Datasource = ".";
                databaseInfo.InitialCatalog = "Codeplus";
                databaseInfo.UserName = "webuser";
                databaseInfo.Password = "London99";
            }
            else
            {
                databaseInfo.Datasource = "sharedmssql.znetindia.net,1234";
                databaseInfo.InitialCatalog = "Codeplus";
                databaseInfo.UserName = "codepluswebuser";
                databaseInfo.Password = "@8*99hmpQC~.";
            }
            return databaseInfo;
        }
    }
}
